<template>
	<view class="forget_pwd">
		<!-- #ifndef MP-WEIXIN -->
		<my-navbar leftText="绑定手机" @leftClick="leftClick"></my-navbar>
		<!-- #endif -->
		<view class="input_info">
			<view class="">
				<view class="sixteen label">手机号码</view>
				<input type="number" v-model="info.mobile" placeholder="请输入手机号码" placaholder-class="placehoder_class" />
			</view>
			<view class="">
				<view class="sixteen label">密码</view>
				<input type="password" v-model="info.password" placeholder="请输入六位及以上的密码" placaholder-style="font-size:15px;" />
			</view>
		</view>
		<view class="form_submit">
			<view class="button" @click="submit">提交</view>
		</view>
	</view>
</template>

<script>
	import {$https} from '@/static/js/request.js';
	export default {
		data() {
			return {
				background: {
					backgroundColor: 'F6F6F7'
				},
				info:{
					password:'',
					mobile:'',
					user_openid:'',
				}
			}

		},
		onLoad(options){
			if(options.user_openid){
				this.info.user_openid = options.user_openid;
			}
		},
		methods: {
			submit(){
				let volid = this.volidInfo();
				if(volid){
					let data = JSON.parse(JSON.stringify(this.info));
					$https('POST','wxLoginFollow',data,res=>{
						if(res.data.errcode == 0){
							uni.setStorageSync("copartner_token", res.data.data.token);
							uni.switchTab({
								url:'/pages/tabar/index'
							})
						}
						else if(res.data.errcode==60021){
							uni.showModal({
								content:'账号已绑定其他微信，确认更换为当前微信吗?',
								success: (re)=> {
									if (re.confirm) {
										Object.assign(data,{confirm:1})
										$https('POST','wxLoginFollow',data,result=>{
											if(result.data.errcode==0){
												uni.setStorageSync("copartner_token", result.data.data.token);
												uni.switchTab({
													url:'/pages/tabar/index'
												})
											}else{
												this.$u.toast(result.data.errmsg);
											}
										},true)
									} else if (re.cancel) {
										
									}
								}
							})
						}
						else{
							this.$u.toast(res.data.errmsg);
						}
					},true)
				}
			},
			//验证表单
			volidInfo(){
				let info = this.info;
				let checkphone =  this.volidPhone();
				if(!checkphone){return false;}
				else if(!info.password){this.$u.toast('请输入密码');return false;}
				else return true;
			},
			//验证手机号
			volidPhone(){
				if(!this.info.mobile){
					this.$u.toast('请输入手机号');
					return false;
				}
				else if(!(/^((0\d{2,3}-\d{7,8})|(1[23567894]\d{9}))$/.test(this.info.mobile))){
					uni.showToast({
						title: '手机号格式错误',
						icon: 'none'
					});
					return false;
				}
				return true;
			},			
			leftClick() {
				// #ifdef H5
				window.history.back(-1);
				// #endif 
				// #ifndef H5
				uni.navigateBack({
					delta: 1
				});
				// #endif
			},
			
		},
		onShow() {

		}
	}
</script>

<style lang="scss" scoped>
	.forget_pwd {
		.input_info {
			padding: 14rpx 34rpx 0;
	
			input {
				border-bottom: 1px solid #ECECEC;
				width: 100%;
				font-size: 26rpx;
				padding: 6px 0 1px;
				font-size: 24rpx;
				
			}
			.label{
				font-size: 32rpx;
				color:#191919;
			}
		}
	
		.input_info>view {
			margin-top: 20rpx;
	
			input {
				margin-top: 6rpx;
			}
		}
	
		.get_code {
			display: flex;
			justify-content: space-between;
			align-items: center;
	
			text {
				position: absolute;
				right: 20rpx;
				background: #B3B3B3;
				padding: 6rpx 10rpx;
				color: $white;
				border-radius: 8rpx;
			}
		}
	}
	
	.placehoder_class {
		font-size: 50rpx;
		color:#C0C0C0;
	}
	
	.forget_pwd {
		.now_login {
	
			margin: 12px 0 31px;
			color: #9a9a9a;
		}
	
		.agreement {
			color: #59A88F;
		}
	}
	.form_submit{
		margin-top:100rpx;
	}
	
	@media(max-width:600px){
		.forget_pwd_val{margin-bottom: 40rpx;}
	}
</style>
